/**
 * 部门js
 */
var userInfoReport = {
	curPage : 0,
	pageSize : 10,
	dataCache : null,

	startEvent : function() {
		// 按回车键登录事件
		document.onkeydown = function(e) {
			var ev = document.all ? window.event : e;
			if (ev.keyCode == 13) {
				userInfoReport.curPage = 1;
				userInfoReport.setPageChange(null);
				userInfoReport.search();
			}
		};
		
		jsUtils.controlFunctionBtn();
	},

	bindEvent : function() {
		// 查询
		$('#refresh').click(function() {
			userInfoReport.curPage = 1;
			userInfoReport.setPageChange(null);
			userInfoReport.search();
		});

		 
		
		$('#cleanRedis').on('click', function() { 
			var url = 'mgr/hcOrder/updateRedisOrder';
			var params = {
					 
			};
			var cb = function(data) {
				//userInfoReport.setPageChange(null);
				//userInfoReport.search();
			}
			sendApiNoLoad(url, params, cb, 'GET');
		});
		
		
		$('#recheck').on('click', function() { 
			var url = 'mgr/orderCheck/reCheck';
			var params = {
					 
			};
			var cb = function(data) {
				userInfoReport.setPageChange(null);
				userInfoReport.search();
			}
			sendApiNoLoad(url, params, cb, 'GET');
		});
		
		
	},

	// 设置分页
	setPageChange : function(delCurPage) {
		var url = 'mgr/orderCheck/getList';
	
		if (typeof (pageIdx) != "undefined") {
			userInfoReport.curPage = pageIdx;
		}
		var params = {
		 
		};

		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / userInfoReport.pageSize > 0) ? Math
						.ceil(totalCount / userInfoReport.pageSize) : 1;
				pageHelper.init(pageTotal, totalCount, userInfoReport.search,
						delCurPage); // 翻页事件
			}
		};
		sendApiNoLoad(url, params, cb, 'GET');
	},

	// 查询交易记录
	search : function(pageIdx) {
		var url = 'mgr/orderCheck/getList';
		if (typeof (pageIdx) != "undefined") {
			userInfoReport.curPage = pageIdx;
		}
		
		var params = {
		};
		
		var cb = function(data) {
			$('#tableList tbody').empty();
			var tr = '';
			if (data.result != null && data.result.length > 0) {
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					
					tr += '<tr><td><input type="hidden" name="id" value="'
							+ singleObj.userId
							+ '"/>'
							+ (i + 1)
							+ '</td><td>'
							+ singleObj.id
							+ '</td><td>'
							+ singleObj.payStatusStr
							+ '</td><td>'
							+ singleObj.orderCreatedOnStr
							+ '</td><td>'
							+ singleObj.productCode
							+ '</td><td>'
							+ singleObj.productName
							+ '</td><td>'
							+ singleObj.productCompanyName
							+ '</td><td>'
							+ singleObj.userName
							+ '</td><td>'
							+ singleObj.userPhoneNum
						 	+ '</td></tr>';
				}
			} else {
				tr = '<tr><td colspan="9" style="text-align: center;color: red;">暂无待确认中的数据</td></tr>';
			}
			$('#tableList tbody').html(tr);
			userInfoReport.bindEventOtherBtn();
			jsUtils.controlFunctionBtn();
		};

		sendApiNoLoad(url, params, cb, 'GET');
	},

	bindEventOtherBtn : function() {
		
	},

	init : function() {
		jsUtils.controlFunctionBtn();
		userInfoReport.setPageChange(null);
		userInfoReport.search();
		userInfoReport.startEvent();
		userInfoReport.bindEvent();
		
	}
};

$(document).ready(function() {
	userInfoReport.init();
});

//提供给外部刷新调用
function refashData() {
	userInfoReport.setPageChange(null);
	userInfoReport.search();
}
